package com.neasho.neashoadminv1.infrastructure.domain.base

import com.neasho.neashoadminv1.infrastructure.domain.YesOrNo
import com.neasho.neashoadminv1.infrastructure.domain.sys.SysUser
import org.babyfish.jimmer.sql.DissociateAction
import org.babyfish.jimmer.sql.GeneratedValue
import org.babyfish.jimmer.sql.GenerationType
import org.babyfish.jimmer.sql.Id
import org.babyfish.jimmer.sql.JoinColumn
import org.babyfish.jimmer.sql.ManyToOne
import org.babyfish.jimmer.sql.MappedSuperclass
import org.babyfish.jimmer.sql.OnDissociate
import java.time.LocalDateTime

/**
 * 基础的entity字段集合
 */
@MappedSuperclass
interface BaseEntity {
    /**
     * ID
     */
    @Id
    @GeneratedValue(
        strategy = GenerationType.IDENTITY
    )
    val id: Long

    /**
     * 创建时间
     */
    val createAt: LocalDateTime

    /**
     * 最后一次更新时间
     */
    val lastModifyAt: LocalDateTime

    /**
     * 创建人
     */
    @ManyToOne
    @JoinColumn(name = "create_by")
    @OnDissociate(DissociateAction.SET_NULL)
    val createBy: SysUser?

    /**
     * 最后一次更新人
     */
    @ManyToOne
    @JoinColumn(name = "last_modify_by")
    @OnDissociate(DissociateAction.SET_NULL)
    val lastModifyBy: SysUser?

    /**
     * 逻辑删除开关: yes逻辑删除，no未逻辑删除
     */
    val delFlag: YesOrNo
        get() = YesOrNo.no
}